package com.webauto.util;


import java.util.Collections;

import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.collections.Lists;

/**
 * PS:用例执行后重制重跑次数
 * @author lkk
 *
 */
public class TestRunnerListener extends TestListenerAdapter {
	/**
	 * PS:用例执行成功后重制重跑次数
	 */
	@Override
	public void onTestSuccess(ITestResult tr) {
		//通过监听对象获取重写的监听器类
		@SuppressWarnings("deprecation")
		TestNGRetry retryAnalyzer = (TestNGRetry) tr.getMethod().getRetryAnalyzer();
		//重制重跑次数为1
		retryAnalyzer.reSetCount();
		Collections.synchronizedList(Lists.newArrayList()).add(tr.getMethod());
		Collections.synchronizedList(Lists.newArrayList());
	}
	/**
	 * PS:用例执行失败后重制重跑次数
	 */
	@Override
    public void onTestFailure(ITestResult tr) {
		//通过监听对象获取重写的监听器类
    	@SuppressWarnings("deprecation")
		TestNGRetry retryAnalyzer = (TestNGRetry) tr.getMethod().getRetryAnalyzer();
    	//重制重跑次数为1
		retryAnalyzer.reSetCount();
		Collections.synchronizedList(Lists.newArrayList()).add(tr.getMethod());
		Collections.synchronizedList(Lists.newArrayList());
    }
}
